package cn.yitun.chat.yitunserverimcore.general.main.push.user;

import cn.yitun.chat.yituncommonmessage.push.PushMessage;
import cn.yitun.chat.yituncommonutil.YitunStringUtil;
import cn.yitun.chat.yitunservercommonlib.constant.ActionTypeConstant;
import cn.yitun.chat.yitunservercommonlib.enums.control.push.user.UserPushMethodEnum;
import cn.yitun.chat.yitunserverimcore.bridge.net.WriteHandler;
import cn.yitun.chat.yitunserverimcore.general.common.util.PushMessageBuild;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 用户信息推送
 * @author yitun
 * @since 1.1
 */
@Service
public class UserPush {
	//1.1.002
	final String action = ActionTypeConstant.USER_ACTION_PUSH;

	@Resource
	WriteHandler writeHandler;

	/**
	 * 
	 * Date 2019-01-26 10:57:37<br>
	 * Description 推送用户信息修改
	 * 
	 * @author yitun<br>
	 * @param key
	 * @param userId
	 * @param userIdList
	 * @version 1.1
	 */
	public void pushUserUpdate(Long key, Long userId, List<Long> userIdList) {
		String method = UserPushMethodEnum.PUSH_USER_UPDATE.getMethod();
		PushMessage message = PushMessageBuild.build(key, action, method);
		message.bodyPut("userId", userId);
		writeHandler.push(YitunStringUtil.toStrList(userIdList), message);
	}

	/**
	 * 
	 * Date 2019-01-26 11:00:24<br>
	 * Description 推送用户头像修改信息
	 * 
	 * @author yitun<br>
	 * @param key
	 * @param userId
	 * @param userIdList
	 * @version 1.1
	 */
	public void pushUserUpdateHead(Long key, Long userId, List<Long> userIdList) {
		String method = UserPushMethodEnum.PUSH_USER_UPDATE_HEAD.getMethod();
		PushMessage message = PushMessageBuild.build(key, action, method);
		message.bodyPut("userId", userId);
		writeHandler.push(YitunStringUtil.toStrList(userIdList), message);
	}

	public void pushUserUpdateSignature(Long key, Long userId, String signature, List<Long> userIdList) {
		String method = UserPushMethodEnum.PUSH_USER_UPDATE_SIGNATURE.getMethod();
		PushMessage message = PushMessageBuild.build(key, action, method);
		message.bodyPut("userId", userId);
		message.bodyPut("signature", signature);
		writeHandler.push(YitunStringUtil.toStrList(userIdList), message);
	}

	/**
	 * 
	 * Date 2019-01-26 10:59:18<br>
	 * Description 推送用户在先状态变化
	 * 
	 * @author yitun<br>
	 * @param key
	 * @param userId
	 * @param chatOnline
	 * @param userIdList
	 * @version 1.1
	 */
	public void pushUserStatus(Long key, Long userId, String chatOnline, List<Long> userIdList) {
		String method = UserPushMethodEnum.PUSH_USER_STATUS.getMethod();
		PushMessage message = PushMessageBuild.build(key, action, method);
		message.bodyPut("userId", userId);
		message.bodyPut("chatOnline", chatOnline);
		writeHandler.push(YitunStringUtil.toStrList(userIdList), message);
	}
}
